import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaLocaleProvider, WeaTable, WeaInputNumber, WeaCheckbox, WeaSearchGroup, WeaInput } from 'ecCom';
const toJS = mobx.toJS;
const getLabel = WeaLocaleProvider.getLabel;
@inject('planProgramViewStore')
@observer
export default class Cube extends React.Component {
  constructor(props) {
    super(props);
    this.state = { searchGroupVisible: true, searchGroupPreviewVisible: true,
      hasLoad:false,
      isShowCube:true,
    };
    this.store = this.props.planProgramViewStore;
    this.saveRef = ref => {
      this.refDom = ref;
    };
  }

  componentDidMount() {
    this.initCube()
  }
  //初始化建模
  initCube = () => {
    const cubeFiles = [
      `/spa/cube/static4engine/engine.js`,
      `/spa/cube/static4engine/engine.css`,
    ];
    const init = () => {
      this.setState((state, props) => ({ hasLoad: true }), () => {
        const { hasLoad } = this.state;
        if (hasLoad) {
          const { EcmeBaseStore, CubeModeStore, CubeCommonStore } = (window.weaCubeEngine && window.weaCubeEngine.store) || {};
          this.setState({
            EcmeBaseStore,
            CubeModeStore,
            CubeCommonStore
          })
        }
      });
    }
    loadjs.isDefined("bs_cube")
      ? loadjs.ready("bs_cube", init)
      : loadjs(cubeFiles, "bs_cube", init);
  }
  cubeCallback = (param) => {
    if(param.type==1){//新建 
      this.store.setState("iscube","1")
      this.store.saveTemplateConfig()
    }else if (param.type==2){//删除
      this.store.saveTemplateConfig()
    }else if(param.type==3){//保存
      this.store.setState("iscube","1")
      this.store.saveTemplateConfig()
    }
  }
  render() {
    let {hasLoad} = this.state
    let { resourceid ,resourcetype,cubeResourceType,isopencube,iscube} = this.store;
    let EcmeSet = (window.weaCubeEngine && window.weaCubeEngine.com && window.weaCubeEngine.com.EcmeSet) || {};
    return (
      <div ref={this.saveRef}>
       {  hasLoad  &&<EcmeSet ecId={`${this && this.props && this.props.ecId || ''}_EcmeSet@wj72c2`} query="workrelateplan" hideTop="1"  ispart="1" partType={cubeResourceType} partid={resourceid} callback={this.cubeCallback}/>}
      </div>
    );
  }
}
